package com.ltx.controller;

import com.ltx.pojo.User;
import com.ltx.service.UserService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class UserController {
    private final UserService userService;

    public UserController(@Qualifier("userServiceImpl") UserService userService) {
        this.userService = userService;
    }

    //跳转至登录界面
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }
    //判断用户是否存在和密码是否正确,用于用户登录判断
 @RequestMapping("/loginTest")
    public String judge(@RequestParam("name")String name, @RequestParam("password") String password, Model model) {
     User user = userService.queryUserByName(name);
    if(user==null)
    {
        model.addAttribute("msg","不存在该用户");
        return "login";
    }
    if(!user.getUserPassword().equals(password)){
        model.addAttribute("msg","密码错误");
        return "login";
    }
     return "ManagePages";
 }
}
